package com.retrofit.demo.utils;

import com.retrofit.demo.Constant.UrlConstant;
import com.retrofit.demo.entity.MovieEntity;
import com.retrofit.demo.entity.ResponseBody;
import com.retrofit.demo.service.MovieService;

import java.io.File;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * <h3>Description</h3>
 * TODO
 * <h3>Author</h3> Louis
 * <h3>Date</h3> 2018/7/14 19:22
 * <h3>Copyright</h3> Copyright (c) 2018 Shenzhen ChinaSoft International Co., Ltd. Inc. All rights reserved.
 */
public class RequestUtil {

    public static final String TEXT_TYPE = "";

    public static void  testMuiltpart(File file){

      Retrofit retrofit = new Retrofit
              .Builder()
              .addConverterFactory(GsonConverterFactory.create())
              .baseUrl("")
              .build();


        MovieService movieService = retrofit.create(MovieService.class);

        RequestBody requestBody = RequestBody.create(MediaType.parse(TEXT_TYPE),"");

        MultipartBody.Part part = MultipartBody.Part.createFormData("file", "test.txt", requestBody);
        movieService.testMuiltpart(requestBody,part);

    }



    public static void testTranslate(){
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(UrlConstant.BSEE_FY)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        MovieService movieService = retrofit.create(MovieService.class);
        Call<ResponseBody> call = movieService.testTranslate("北京");
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody body = response.body();
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {

            }
        });

    }



    public static  void getMovieList2(){
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(UrlConstant.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();

        MovieService movieService = retrofit.create(MovieService.class);

        movieService.getMovieList2(1,5)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<MovieEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(MovieEntity movieEntity) {
                        MovieEntity result = movieEntity;
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

}
